﻿#include "OiPCH.hpp"
#include <QApplication>
#include <QTextCodec>
#include <QDesktopWidget>
#include <QInputDialog>
#include <QCryptographicHash>
#include <QMessageBox>
#include <QSharedMemory>

#include "Base/OiDefines.hpp"
#include "Base/OiGlobals.hpp"
#include "Core/OiCore.hpp"
#include "Core/OiSettings.hpp"

using namespace Oi;

extern "C"
{
    int __declspec(dllexport) Entry(int argc, char* argv[])
    {

        QApplication::setOrganizationName("LeaderTech");
        QApplication::setApplicationName("PLScanner");
        QApplication::setApplicationVersion("1.0");

        QSharedMemory identifier;

        identifier.setKey("OiPLScanner");

        if (identifier.attach())
        {
            identifier.detach();
            return 0;
        }

        if (identifier.create(1))
        {
        }

        Core::Instance core;

        Core::OiSetTarget(OiMonitor);

        QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
        QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);

        QApplication app(argc, argv);

        app.setStyle("ribbonstyle");

        auto settings = Core::OiSettings();

        QString locale = settings->locale();

        auto qtTranslator = new QTranslator(&app);
        if (qtTranslator->load("qt_" + locale, "languages"))
        {
            qApp->installTranslator(qtTranslator);
        }
        else
        {
            delete qtTranslator;
        }

        auto oiTranslator = new QTranslator(&app);
        if (oiTranslator->load("oi_" + locale, "languages"))
        {
            qApp->installTranslator(oiTranslator);
        }
        else
        {
            delete oiTranslator;
        }

        auto inspectorTranslator = new QTranslator(&app);
        if (inspectorTranslator->load("PLScanner_" + locale, "languages"))
        {
            qApp->installTranslator(inspectorTranslator);
        }
        else
        {
            delete inspectorTranslator;
        }

        Appl::Instance appl;

        PLScannerDll::PLScannerWindow window;

        window.show();

        return app.exec();
    }
}